﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.OpenGL.Native.Vectors;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace Silvermoon.OpenGL.Native
{
    public static partial class gl
    {
        [DllImportAttribute(LibGlesDllName, EntryPoint = "glVertexPointer")]
        public unsafe static extern void VertexPointer(int size, glValueType type, int stride, void* vectors);

        [DllImportAttribute(LibGlesDllName, EntryPoint = "glVertexPointer")]
        public static extern void VertexPointer(int size, glValueType type, int stride, Array vectors);


        public static void VertexPointer(Vector2i[] vectors)
        {
            VertexPointer(2, glValueType.Fixed, 0, vectors);
        }

        public static void VertexPointer(Vector3i[] vectors)
        {
            VertexPointer(3, glValueType.Fixed, 0, vectors);
        }


        public static void VertexPointer(Vector2s[] vectors)
        {
            VertexPointer(2, glValueType.Short, 0, vectors);
        }

        public static void VertexPointer(Vector3s[] vectors)
        {
            VertexPointer(3, glValueType.Short, 0, vectors);
        }



        public static void VertexPointer(Vector2f[] vectors)
        {
            IntPtr ptr = new IntPtr();
            Marshal.StructureToPtr(vectors, ptr, true);
            VertexPointer(2, glValueType.Float, 0, ptr);
        }

        public static void VertexPointer(Vector3f[] vectors)
        {
            IntPtr ptr = new IntPtr();
            Marshal.StructureToPtr(vectors, ptr, true);
            VertexPointer(3, glValueType.Float, 0, ptr);
        }


        [DllImportAttribute(LibGlesDllName, EntryPoint = "glTexCoordPointer")]
        internal unsafe static extern void TexCoordPointer(int size, glValueType type, int stride, void* vectors);


        [DllImportAttribute(LibGlesDllName, EntryPoint = "glTexCoordPointer")]
        internal static extern void TexCoordPointer(int size, glValueType type, int stride, Array vectors);

        public static void TexCoordPointer(Vector2s[] vectors)
        {
            TexCoordPointer(2, glValueType.Short, 0, vectors);
        }

        public static void TexCoordPointer(Vector2i[] vectors)
        {
            TexCoordPointer(2, glValueType.Fixed, 0, vectors);
        }

        public static void TexCoordPointer(Vector2b[] vectors)
        {
            TexCoordPointer(2, glValueType.Byte, 0, vectors);
        }


        [DllImportAttribute(LibGlesDllName, EntryPoint = "glColorPointer")]
        private unsafe static extern void ColorPointer(int size, glValueType type, int stride, void* vectors);



        public unsafe static void VertexColorPointer(VCVector2s[] vectors)
        {
            fixed (void* v = &vectors[0])
            {
                VertexPointer(2, glValueType.Short, 8, v);
            }
            fixed (void* c = &vectors[0].ColorValue)
            {
                ColorPointer(4, glValueType.UnsignedByte, 8, c);
            }
        }

        public unsafe static void VertexColorPointer(VCVector2i[] vectors)
        {
            fixed (void* v = &vectors[0])
            {
                VertexPointer(2, glValueType.Short, 12, v);
            }
            fixed (void* c = &vectors[0].ColorValue)
            {
                ColorPointer(4, glValueType.UnsignedByte, 12, c);
            }
        }
    }
}
